diff options
| author | Adam Soltys <[email protected]> | 2022-10-26 15:32:32 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-26 15:32:32 -0700 |
| commit | 12b660de8e9430d44bf56357decd6c8e63d24025 (patch) | |
| tree | 5eac98dd0c1d354a4cc179ce1856021e70f05061 /src/routes/[username]/transactions | |
| parent | d01f85627869e7c2e4b83c7259c6fb2b8e13d562 (diff) | |
| download | coinos-ui-12b660de8e9430d44bf56357decd6c8e63d24025.tar.gz coinos-ui-12b660de8e9430d44bf56357decd6c8e63d24025.zip | |
pagination fixes
Diffstat (limited to 'src/routes/[username]/transactions')
| -rw-r--r-- | src/routes/[username]/transactions/[...page]/+page.server.js | 20 | ||||
| -rw-r--r-- | src/routes/[username]/transactions/[...page]/+page.svelte | 36 |
2 files changed, 38 insertions, 18 deletions
diff --git a/src/routes/[username]/transactions/[...page]/+page.server.js b/src/routes/[username]/transactions/[...page]/+page.server.js index caa2e155..95fb8094 100644 --- a/src/routes/[username]/transactions/[...page]/+page.server.js +++ b/src/routes/[username]/transactions/[...page]/+page.server.js @@ -1,6 +1,6 @@ import { get, auth } from '$lib/utils'; -let offset = 25; +let limit = 25; export async function load({ cookies, params, request }) { let parts = params.page.split('/'); @@ -11,16 +11,16 @@ export async function load({ cookies, params, request }) { if (parts.length === 3) [start, end, page] = parts; if (!parseInt(page)) page = 1; - let url = '/payments'; - if (start && end) url += `?start=${start}&end=${end}`; - else if (start) url += `?start=${start}`; - else if (end) url += `?end=${end}`; + let offset = (page-1) * limit; + + let url = `/payments?v2=true&limit=${limit}&offset=${offset}`; + if (start) url += `&start=${start}`; + if (end) url += `&end=${end}`; + + let { total, transactions } = await get(url, auth(cookies)); + console.log("TOT", total, transactions.length); + let pages = new Array(Math.ceil(total / limit)); - let transactions = await get(url, auth(cookies)); - let total = transactions.length; - let pages = new Array(Math.ceil(total / offset)); - let i = (page - 1) * offset; - transactions = transactions.slice(i, i + offset); return { total, transactions, page, pages, start, end }; } diff --git a/src/routes/[username]/transactions/[...page]/+page.svelte b/src/routes/[username]/transactions/[...page]/+page.svelte index cf809445..71314e88 100644 --- a/src/routes/[username]/transactions/[...page]/+page.svelte +++ b/src/routes/[username]/transactions/[...page]/+page.svelte @@ -7,21 +7,23 @@ import { f, s, sats } from '$lib/utils'; import { page } from '$app/stores'; import { differenceInDays, getUnixTime, sub } from 'date-fns'; + import { goto } from '$app/navigation'; export let data; let { start, end, user } = data; + let change = ({ target: { value } }) => goto(value); let presets = [ - { title: 'Today', start: sub(new Date(), { days: 1 }), end: null }, - { title: '7 days', start: sub(new Date(), { days: 7 }), end: null }, - { title: 'Last month', start: sub(new Date(), { months: 1 }), end: null }, - { title: 'All', start: null, end: null } + { title: 'Today', start: null, end: null }, + { title: 'Week', start: sub(new Date(), { days: 7 }), end: null }, + { title: 'Month', start: sub(new Date(), { months: 1 }), end: null }, + { title: 'All', start: sub(new Date(), { years: 5 }), end: null } ]; $: selection = start ? presets.findIndex((p) => Math.abs(differenceInDays(new Date(start * 1000), p.start)) < 1) - : presets.length - 1; + : 0; let p, total, @@ -32,6 +34,9 @@ $: $page && ($newPayment = false); $: $newPayment && invalidate(`/users/${user.username}`); + $: path = $page.url.pathname.substring(0, $page.url.pathname.lastIndexOf('/')); + $: console.log(path) + let csv = () => { const keys = ['hash', 'updatedAt', 'rate', 'currency', 'amount', 'fee', 'tip']; const csv = @@ -63,9 +68,18 @@ {$t('user.transactions.header')} </h1> - <div class="container w-full mx-auto md:text-lg px-10 lg:px-72"> + <div class="container w-full mx-auto md:text-lg px-4 max-w-xl"> <div class="flex text-md text-secondary flex-wrap mb-4"> - <div class="flex flex-wrap gap-2"> + <select class="md:hidden bg-white border p-4 rounded-full" on:change={change}> + {#each presets as { start, end, title }, i} + <option + selected={selection === i} + value={`/${user.username}/transactions/${start ? getUnixTime(start) + '/' : ''}1`} + >{title}</option + > + {/each} + </select> + <div class="hidden md:block flex flex-wrap gap-2"> {#each presets as { start, end, title }, i} <a class:active={selection === i} @@ -88,7 +102,7 @@ {#each pages as _, i} <a class="mr-1 last:mr-0" - href={`/${user.username}/transactions/${i + 1}`} + href={`${path}/${i + 1}`} class:active={parseInt(p) === i + 1} > <div class="border py-2 rounded-full border-2 w-12 h-12 hover:opacity-80 text-center"> @@ -145,4 +159,10 @@ .active * { @apply bg-black text-white border-black; } + + select { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + } </style> |
